/**
 * 
 */
package reco.db.validation;

import static org.apache.commons.lang.StringUtils.isBlank;

import org.apache.commons.validator.UrlValidator;

import reco.db.Constraint;

import com.google.common.base.Preconditions;

/**
 * @author juanjo
 */
public class UrlConstraint extends Constraint<String> {

    private final UrlValidator validator;

    /**
     * @param field
     * @param constraintName
     * @param constraintMessage
     */
    public UrlConstraint(UrlValidator validator) {
        super("urlConstraint", "#isNotUrl");
        this.validator = Preconditions.checkNotNull(validator);
    }

    @Override
    public boolean validate(String value) {
        if (isBlank(value)) {
            return true;
        }
        return this.validator.isValid(value);
    }

    @Override
    public Object[] getErrorArguments() {
        return null;
    }

}
